/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.dao.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.cx1.dao.api.IMobileInviteeDao;
import org.cx1.model.utils.MobileInvitee;
import org.cx1.model.utils.MobileInvitee;

/**
 *
 * @author ECH
 */
public class MobileInviteeDao implements IMobileInviteeDao {

    private SqlMapClient sqlMapClient;

    public MobileInviteeDao() {
        sqlMapClient = IbatisConnectionFactory.getSqlMapClient();
    }
    
    @Override
    public List<MobileInvitee> getAll() {
        List<MobileInvitee> mobileInvitees = new ArrayList<MobileInvitee>();        
        try {
            mobileInvitees = sqlMapClient.queryForList("mobileInvitee.getAll");
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return mobileInvitees;
    }

    @Override
    public List<MobileInvitee> getAll(int offset, int limit) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public String add(MobileInvitee mobileInvitee) {
        String mobile = "";        
        try {
            sqlMapClient.insert("mobileInvitee.add", mobileInvitee);
            mobile = mobileInvitee.getMobile();            
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }        
        return mobile;
    }

    @Override
    public int update(MobileInvitee mobileInvitee) {
        int noOfRowsAffected = 0;        
        try {
            noOfRowsAffected = sqlMapClient.update("mobileInvitee.update", mobileInvitee);
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }        
        return noOfRowsAffected;
    }

    @Override
    public int deleteByMobile(String mobile) {
        int noOfRowsAffected = 0;        
        try {
            noOfRowsAffected = sqlMapClient.delete("mobileInvitee.deleteByMobile", mobile);
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }             
        return noOfRowsAffected;
    }

    @Override
    public int setProcessed(String mobile, boolean processed) {
        int noOfRowsAffected = 0;        
        try {
            Map param = new HashMap();
            param.put("mobile", mobile);
            param.put("processed", processed);
            
            noOfRowsAffected = sqlMapClient.update("mobileInvitee.setProcessed", param);
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }        
        return noOfRowsAffected;
    }

    @Override
    public List<MobileInvitee> getAll(boolean processed, int offset, int limit) {        
        List<MobileInvitee> mobileInvitees = new ArrayList<MobileInvitee>();        
        try {
            Map param = new HashMap();
            param.put("processed", processed);
            param.put("offset", offset);
            param.put("limit", limit);
            
            mobileInvitees = sqlMapClient.queryForList("mobileInvitee.getAllByProcessed", param);
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }        
        return mobileInvitees;
    }
    
}
